using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using LLG.SharePoint.Services;
using System.IO;

namespace LLG.SharePoint.SPWebServiceDeployment
{
    public class DiscoverWebServicesFeatureReceiver : SPFeatureReceiver
    {
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            DirectoryInfo myFeature = new DirectoryInfo(properties.Definition.RootDirectory);
            DirectoryInfo Hive12 = myFeature.Parent.Parent.Parent;
            SPWebServiceDeployer wsd = new SPWebServiceDeployer("http://moss2007:25000",
                properties.Feature.Definition.DisplayName,
                Hive12.FullName);
            wsd.GenWebService();
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            DirectoryInfo myFeature = new DirectoryInfo(properties.Definition.RootDirectory);
            DirectoryInfo Hive12 = myFeature.Parent.Parent.Parent;
            SPWebServiceDeployer wsd = new SPWebServiceDeployer("http://moss2007:25000",
                 properties.Feature.Definition.DisplayName,
                 Hive12.FullName);
            wsd.RemoveWebService("HelloWorldWebService.asmx");
        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
            //The manifest (solution) should install NO FILES. All webservice .asmx files 
            //should be in the FEATURE. This allows the webservice to be brought on/offline as needed.
        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
            //Not implementing but not throwing an error.
        }
    }
}
